﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EntityFrameworkETL.Interfaces;
using EntityFrameworkETL.Test.Mocks;
using System.Collections.Generic;
using System.Data.Common;

namespace EntityFrameworkETL.Test
{
    [TestClass]
    public class ETLTest
    {
        private ExecuteBatchCommandsMock ExecuteBatchCommands { get; set; }
        private RepositoryMock Repository { get; set; }

        [TestInitialize]
        public void TestInitialize()
        {
            ExecuteBatchCommands = new ExecuteBatchCommandsMock();
            Repository = new RepositoryMock();
        }

        [TestMethod]
        public void Execute_1000Records_Executes10Commands()
        {
            List<string> mockobjects = new List<string>();
            for (int i = 0; i < 1000; i++)
            {
                mockobjects.Add("");
            }
            Repository.SetSourceItems<string>(mockobjects);
            var etl = new ETL(Repository, ExecuteBatchCommands);
            etl.BatchInserts<string>(100, true);
            Assert.IsTrue(ExecuteBatchCommands.Calls == 10);
        }

        [TestMethod]
        public void Execute_1001Records_Executes10Commands()
        {
            List<string> mockobjects = new List<string>();
            for (int i = 0; i < 1001; i++)
            {
                mockobjects.Add("");
            }
            Repository.SetSourceItems<string>(mockobjects);
            var etl = new ETL(Repository, ExecuteBatchCommands);
            etl.BatchInserts<string>(100, true);
            Assert.IsTrue(ExecuteBatchCommands.Calls == 11);
        }
    }
}
